package com.lgkj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgkj.R;
import com.lgkj.bean.CityBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/12/5 0005.
 */

public class CityChoiceAdapter extends BaseAdapter {
    private Context context;
    private List<CityBean.DataBean> beans;

    @Override
    public int getCount() {
        return beans.size();
    }

    public void setBeans(List<CityBean.DataBean> bean) {
        this.beans = bean;
        notifyDataSetChanged();
    }

    public CityChoiceAdapter(Context context) {
        this.context = context;
        beans = new ArrayList<>();
    }

    @Override
    public CityBean.DataBean getItem(int position) {
        return beans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_choice_city, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvHomes.setText(beans.get(position).getName());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_homes)
        TextView tvHomes;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
